# coding: utf-8
from __future__ import unicode_literals

from keras.models import  Sequential
from keras.layers import  Embedding,GlobalAveragePooling1D,Dense

VOCAB_SIZE = 2000
EMBEDDING_DIM = 100
MAX_WORDS = 500
CLASS_NUM = 5

def bulid_fastText():
    model = Sequential()
    # 通过embedding层，我们将词汇映射成EMBEDDING_DIM维向量
    model.add(Embedding(VOCAB_SIZE,EMBEDDING_DIM,input_length=MAX_WORDS))
    # 通过GlobalAverangePoolingID，我们平均了文档所有词的embedding
    model.add(GlobalAveragePooling1D())
    # 通过输出Softmax分类（真实的fastText这里是分层softmax)，得到类别概率分布
    model.add(Dense(CLASS_NUM,activation='softmax'))
    # 定义损失函数、优化器、分类都理想指标
    model.compile(loss='categorical_crossentropy',optimizer='SGD',metrics='accuracy')
    return model

if __name__ == '__main__':
    model = bulid_fastText()
    print(model.summary())